/* 
** 
** @copyright inovia
** @version	1.0
**makeFormRequest(col)
** 
** replace a SPAN tag (col) by a form to send a request
**
** @param dspan : the specified tag (object)
** @param order,orderkind,page,numpage : spcecif parameters for the request
*/

function makeFormRequest(dspan,order,orderkind,page,numpage){
	// we get the name of the column
	var colName=dspan.innerHTML;

	//we create a form / input / submit
	var dform=document.createElement('form');
	dform.method="GET";
	dform.id="formRequest_"+colName;
	dform.action="javascript:sendFormRequest('"+colName+"','"+order+"','"+orderkind+"','"+page+"','"+numpage+"')";
	dform.setAttribute("class","formRequest_form");
	var dinput=document.createElement('input');
	dinput.type="text"
	dinput.value="";
	dinput.setAttribute("class","formRequest_input");
	dinput.setAttribute("onblur","setTimeout(\"renameFormRequest('formRequest_"+colName+"','"+colName+"','"+order+"','"+orderkind+"','"+page+"','"+numpage+"')\",200)");
	var dsubmit=document.createElement('input');
	dsubmit.type="submit";
	dsubmit.value="Ok";
	dsubmit.setAttribute("class","formRequest_submit");
	// append
	dform.appendChild(dinput);
	dform.appendChild(dsubmit);

	//we replace the span by the form
	dspan.parentNode.replaceChild(dform, dspan);
  dinput.focus();
}

/* sendFormRequest(col)
** 
** send a request using the content of the form given in parameter
**
** @param colName : the specified tag (object)
** @param order,orderkind,page,numpage : spcecif parameters for the request
*/
function sendFormRequest(colName,order,orderkind,page,numpage){
	dform=G("formRequest_"+colName);
	// we get the request
	var request=dform.firstChild.value;

	//we launch the request
  window.location="index.php?action=homeUsers&order="+order+"&orderkind="+orderkind+"&page="+page+"&numpage="+numpage+"&parameter="+colName+"&value="+request;

}

function renameFormRequest(dinputID,colName,order,orderkind,page,numpage){
	var dform=G(dinputID);
	var dspan=document.createElement('span');
	dspan.setAttribute('onclick',"makeFormRequest(this,'"+order+"','"+orderkind+"','"+page+"','"+numpage+"')");
	dspan.setAttribute('class',"users_column");
	dspan.innerHTML=colName;

	//we replace the form by the span
	dform.parentNode.replaceChild(dspan, dform);
}
